﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;

public partial class RoleSecurity : System.Web.UI.Page
{
    DataSet dseInputInfo = new DataSet();
    DataSet dsePageInfo = new DataSet();
    DataSet dsChildElement;
    HtmlForm frmObj;
    security hdds;
    string strPagesetRowId;

    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = Session["theme"].ToString();
        this.Title = "MaxBlox";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        hdds = new security();
        lblMessage.Text = "";
        if (Session["userid"] == null) Response.Redirect(hdds.SessionExpiryURL);
        if (Session["userid"].ToString() == "") Response.Redirect(hdds.SessionExpiryURL);

        string strErrorMsg = "";
        if (!hdds.IsValidPageURL(ref strErrorMsg))
        {
            lblMessage.Text = wrapItAsMessage(strErrorMsg, true);
            TABLE1.Visible = false;
            return;
        }

        if (Request.QueryString["mn"] != null)
            hdds.logMenuClick(Request.QueryString["mn"].ToString());

        if (this.Master.FindControl("Form1") != null)
            frmObj = (HtmlForm)this.Master.FindControl("Form1");

        strPagesetRowId = Request.QueryString["pgs_id"].ToString();

        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);

        LoadChildElements();
        if (!Page.IsPostBack)
        {
            LoadDashboardCombo();
            loadOwneridDropDown();
            CheckForChangeOwner();
            checkEditOperation();
            getpageicons();
        }

        AddPageToolTip(dsePageInfo.Tables["Page"].Rows[0], ref lblHeader);
        isViewMode();
    }

    private void LoadChildElements()
    {
        HDDatabase HDD = new HDDatabase();
        string strRoleId = "";
        try
        {
            if (Request.QueryString["PK"] != null)
                strRoleId = Request.QueryString["PK"].ToString();
            dsChildElement = HDD.GetDataset("SELECT a.af_row_id, a.menu_id, a.menu_name, b.is_accessible, b.role_id, b.modified_at, b.af_row_id as rol_af_row_id FROM sy_mnu a LEFT JOIN sy_rol_acc b ON a.af_row_id = b.menu_id and b.role_id = '" + strRoleId + "' order by a.menu_name asc;SELECT a.af_row_id, a.object_id, a.object_name, b.role_id, b.[read], b.[create], b.edit, b.[delete], b.change_owner, b.modified_at, b.af_row_id as rol_af_row_id FROM sy_obj a LEFT JOIN sy_obj_acc b ON a.object_id = b.object_id and b.role_id = '" + strRoleId + "' order by a.object_name asc;SELECT a.af_row_id, a.rpt_id, a.rpt_name, b.is_accessible, b.role_id, b.modified_at, b.af_row_id as rol_af_row_id FROM sy_report a LEFT JOIN sy_report_acc b ON a.af_row_id = b.report_id and b.role_id = '" + strRoleId + "' order by a.rpt_name asc;SELECT a.af_row_id, a.link_name, b.is_accessible, b.role_id, b.modified_at, b.af_row_id as rol_af_row_id FROM sy_quick_links a LEFT JOIN sy_quick_link_access b ON a.af_row_id = b.quick_link and b.role_id = '" + strRoleId + "' order by a.link_name asc;");

            bool isView = false;
            if (HttpContext.Current.Request.QueryString["VMODE"] != null)
                if (HttpContext.Current.Request.QueryString["VMODE"] == "1")
                    isView = true;

            HtmlTableRow htr = null;
            HtmlTableCell htc = null;
            foreach (DataTable dt in dsChildElement.Tables)
            {
                if (!dt.Columns.Contains("read"))
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        int intRow = i % 2;

                        htr = new HtmlTableRow();
                        htr.VAlign = "middle";
                        htr.Height = "25px";
                        htr.Attributes.Add("Class", "Grid_Row" + intRow.ToString());
                        htr.Attributes.Add("onMouseOver", "this.className='Grid_Scroll_BG'");
                        htr.Attributes.Add("onMouseOut", "this.className='" + "Grid_Row" + intRow.ToString() + "'");
                
                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "60%";
                        htc.Controls.Add(new LiteralControl("&nbsp;"));
                        if (dt.Columns.Contains("menu_id"))
                            htc.Controls.Add(new LiteralControl(dr["menu_name"].ToString()));
                        else if (dt.Columns.Contains("rpt_id"))
                            htc.Controls.Add(new LiteralControl(dr["rpt_name"].ToString()));
                        else if (dt.Columns.Contains("link_name"))
                            htc.Controls.Add(new LiteralControl(dr["link_name"].ToString()));
                        htr.Cells.Add(htc);

                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "40%";
                        CheckBox chk_access = new CheckBox();
                        chk_access.ID = "chk_access_" + dr["af_row_id"].ToString();
                        //chk_access.Checked = false;
                        if (isView) chk_access.Enabled = false;
                        htc.Controls.Add(chk_access);
                        htr.Cells.Add(htc);

                        if (dt.Columns.Contains("menu_id"))
                            tb_Menu.Rows.Add(htr);
                        else if (dt.Columns.Contains("rpt_id"))
                            tb_report.Rows.Add(htr);
                        else if (dt.Columns.Contains("link_name"))
                            tb_quick_links.Rows.Add(htr);
                    }
                }
                else
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        int intRow = i % 2;

                        htr = new HtmlTableRow();
                        htr.VAlign = "middle";
                        htr.Height = "25px";
                        htr.Attributes.Add("Class", "Grid_Row" + intRow.ToString());
                        htr.Attributes.Add("onMouseOver", "this.className='Grid_Scroll_BG'");
                        htr.Attributes.Add("onMouseOut", "this.className='" + "Grid_Row" + intRow.ToString() + "'");
                
                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "45%";
                        htc.Controls.Add(new LiteralControl("&nbsp;"));
                        htc.Controls.Add(new LiteralControl(dr["object_name"].ToString()));
                        htr.Cells.Add(htc);

                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "10%";
                        CheckBox chk_read = new CheckBox();
                        chk_read.ID = "chk_read_" + dr["af_row_id"].ToString();
                        //chk_read.Checked = false;
                        if (isView) chk_read.Enabled = false;
                        htc.Controls.Add(chk_read);
                        htr.Cells.Add(htc);

                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "10%";
                        CheckBox chk_create = new CheckBox();
                        chk_create.ID = "chk_create_" + dr["af_row_id"].ToString();
                        //chk_create.Checked = false;
                        if (isView) chk_create.Enabled = false;
                        htc.Controls.Add(chk_create);
                        htr.Cells.Add(htc);

                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "10%";
                        CheckBox chk_edit = new CheckBox();
                        chk_edit.ID = "chk_edit_" + dr["af_row_id"].ToString();
                        //chk_edit.Checked = false;
                        if (isView) chk_edit.Enabled = false;
                        htc.Controls.Add(chk_edit);
                        htr.Cells.Add(htc);

                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "10%";
                        CheckBox chk_delete = new CheckBox();
                        chk_delete.ID = "chk_delete_" + dr["af_row_id"].ToString();
                        //chk_delete.Checked = false;
                        if (isView) chk_delete.Enabled = false;
                        htc.Controls.Add(chk_delete);
                        htr.Cells.Add(htc);

                        htc = new HtmlTableCell();
                        htc.VAlign = "middle";
                        htc.Align = "left";
                        htc.Width = "15%";
                        CheckBox chk_change_owner = new CheckBox();
                        chk_change_owner.ID = "chk_change_owner_" + dr["af_row_id"].ToString();
                        //chk_change_owner.Checked = false;
                        if (isView) chk_change_owner.Enabled = false;
                        htc.Controls.Add(chk_change_owner);
                        htr.Cells.Add(htc);

                        tb_object.Rows.Add(htr);
                    }
                }
            }
            if (HttpContext.Current.Session["roleid"].ToString() == "e7029dafbe379f85")
            {
                tab_quick_links.Visible = true;
                tb_quick_links.Visible = true;
                textsearch_qlinks.Visible = true;
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: LoadChildElements() " + ex.Message);
        }
        finally
        {
        }
    }

    private void LoadDashboardCombo()
    {
        BindControl BC = new BindControl();
        HDDatabase hd = new HDDatabase();
        DataTable dt = new DataTable();
        try
        {
            DataRow dr1 = dsePageInfo.Tables["PageCtrl"].Select("control_name = 'Default Dashboard'")[0];
            string strBindRowID = dr1["control_bind_id"].ToString();

            if (strBindRowID != "")
                dt = hd.GetDataTable(BC.GetBindSql(strBindRowID));
            
            p_rol_default_dashboard.Items.Clear();
            p_rol_default_dashboard.Items.Add(new ListItem("", ""));

            if (dt != null)
            {
                foreach (DataRow dr in dt.Select("", "Fld asc"))
                {
                    ListItem liObject = new ListItem(dr["Fld"].ToString(), dr["Val"].ToString());
                    p_rol_default_dashboard.Items.Add(liObject);
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: LoadDashboardCombo() : " + ex.Message);
        }
        finally
        {
            dt.Dispose();
        }
    }

    private bool checkEditOperation()
    {
        bool bEdit = false;
        try
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["PK"] != null)
                {
                    lblHeader.Text = "Role Details - Edit";
                    bEdit = true;
                    if (getData())
                        setData(bEdit);
                    //putPrintButtons();
                }

                if (Request.QueryString["CPY"] != null)
                {
                    if (Request.QueryString["CPY"] == "0")
                    {
                        lblHeader.Text = "Role Details - Copy";
                        bEdit = false;
                    }
                }
                
                if (bEdit)
                {
                    btnSave.Visible = false;
                    btnSave_bottom.Visible = false;
                    btnUpdate.Visible = true;
                    btnUpdate_bottom.Visible = true;
                }
                else
                {
                    btnUpdate.Visible = false;
                    btnUpdate_bottom.Visible = false;
                    btnSave.Visible = true;
                    btnSave_bottom.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :RoleSecurity: checkEditOperation() " + ex.Message);
            return false;
        }
        return true;
    }

    private void disableControls()
    {
        try
        {
            p_rol_role_id.Enabled = false;
            p_rol_role_name.Enabled = false;
            p_rol_default_dashboard.Enabled = false;
            btnSave.Enabled = false;
            btnUpdate.Enabled = false;
            btnSave_bottom.Enabled = false;
            btnUpdate_bottom.Enabled = false;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: disableControls() : " + ex.Message);
        }
    }

    private bool getData()
    {
        HDDatabase hdd = new HDDatabase();
        bool bReturn = true;
        try
        {
            foreach (DataRow dr in dsePageInfo.Tables["page"].Rows)
            {
                string sObject_id = dr["object_id"].ToString();
                if (hdds.getObjectRightsForUser(dr["object_id"].ToString(), "read"))
                {
                    DataTable dt = hdd.GetDataTable("select * from " + dr["page_table_name"].ToString() + " where af_row_id = '" + Request.QueryString["PK"].ToString() + "'");
                    dt.TableName = dr["page_id"].ToString();
                    dseInputInfo.Tables.Add(dt.Copy());
                }
                else
                {
                    disableControls();
                    bReturn = false;
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: getData() : " + ex.Message);
            return false;
        }
        return bReturn;
    }

    private void getpageicons()
    {
        PageIcons icons = new PageIcons();
        HDDatabase Hdd = new HDDatabase();
        try
        {
            lblHeader.Text = "&nbsp;" + icons.geticontextfrompageset(Request.QueryString["pgs_id"].ToString(), 2) + "&nbsp;" + lblHeader.Text;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: getpageicons() " + ex.Message);
            lblHeader.Text = "<img src=" + PageIcons.strdefaulticon.ToString() + "></img>&nbsp;" + lblHeader.Text;
        }
        finally
        {
            icons = null;
            Hdd = null;
        }

    }

    private void setData(bool IsEdit)
    {
        try
        {
            if (dseInputInfo.Tables[0] != null && dseInputInfo.Tables[0].Rows.Count > 0)
            {
                if (IsEdit)
                {
                    if (Request.QueryString["CPY"] != null)
                    {
                        ScreenReader SR = new ScreenReader();
                        p_rol_af_row_id.Value = SR.getHashKey();
                        SR = null;
                        p_rol_owner_id_dd.SelectedValue = Session["user_afrowid"].ToString();
                        p_rol_owner_id.Value = Session["user_afrowid"].ToString();
                        txt_p_rol_owner_id.Text = Session["userid"].ToString();
                    }
                    else
                    {
                        p_rol_af_row_id.Value = dseInputInfo.Tables[0].Rows[0]["af_row_id"].ToString();
                        p_rol_owner_id_dd.SelectedValue = dseInputInfo.Tables[0].Rows[0]["owner_id"].ToString();
                        p_rol_owner_id.Value = dseInputInfo.Tables[0].Rows[0]["owner_id"].ToString();
                        LoadEditPage LEP = new LoadEditPage();
                        txt_p_rol_owner_id.Text = LEP.GetUserIDFromAfrowid(dseInputInfo.Tables[0].Rows[0]["owner_id"].ToString());
                        LEP = null;

                    }
                    p_rol_created_at.Value = dseInputInfo.Tables[0].Rows[0]["created_at"].ToString();
                    p_rol_created_by.Value = dseInputInfo.Tables[0].Rows[0]["created_by"].ToString();
                }
                else
                {
                    ScreenReader sc = new ScreenReader();
                    p_rol_af_row_id.Value = sc.getHashKey();
                    p_rol_owner_id_dd.SelectedValue = Session["userafrowid"].ToString();
                    p_rol_owner_id.Value = Session["user_afrowid"].ToString();
                    txt_p_rol_owner_id.Text = Session["userid"].ToString();
                }
                p_rol_role_id.Text = dseInputInfo.Tables[0].Rows[0]["role_id"].ToString();
                p_rol_role_name.Text = dseInputInfo.Tables[0].Rows[0]["role_name"].ToString();
                p_rol_default_dashboard.SelectedValue = dseInputInfo.Tables[0].Rows[0]["default_dashboard"].ToString();

                if (dsChildElement != null && dsChildElement.Tables.Count > 0)
                {
                    foreach (DataTable dt in dsChildElement.Tables)
                    {
                        if (!dt.Columns.Contains("read"))
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (dr["is_accessible"].ToString() != "" && dr["is_accessible"].ToString() != "False")
                                {
                                    CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_access_" + dr["af_row_id"].ToString());
                                    chkBox.Checked = true;
                                }
                            }
                        }
                        else
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (dr["read"].ToString() != "" && dr["read"].ToString() != "False")
                                {
                                    CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_read_" + dr["af_row_id"].ToString());
                                    chkBox.Checked = true;
                                }
                                if (dr["create"].ToString() != "" && dr["create"].ToString() != "False")
                                {
                                    CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_create_" + dr["af_row_id"].ToString());
                                    chkBox.Checked = true;
                                }
                                if (dr["edit"].ToString() != "" && dr["edit"].ToString() != "False")
                                {
                                    CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_edit_" + dr["af_row_id"].ToString());
                                    chkBox.Checked = true;
                                }
                                if (dr["delete"].ToString() != "" && dr["delete"].ToString() != "False")
                                {
                                    CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_delete_" + dr["af_row_id"].ToString());
                                    chkBox.Checked = true;
                                }
                                if (dr["change_owner"].ToString() != "" && dr["change_owner"].ToString() != "False")
                                {
                                    CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_change_owner_" + dr["af_row_id"].ToString());
                                    chkBox.Checked = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: setData() : " + ex.Message);
        }
    }


    #region PageToolTip
    private void AddPageToolTip(DataRow drpage, ref Label lblHeader)
    {
        try
        {
            if (drpage != null)
            {
                if (!Page.IsPostBack)
                    lblHeader.Text = lblHeader.Text + getTootipIcon(drpage);
                Literal lit = new Literal();
                lit.Text = getTooltipContent(drpage);
                td_Page_ToopTip.Controls.Add(lit);
            }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error : RoleSecurity:  AddPageToolTip() :" + e.Message);
        }
    }
    private string getTootipIcon(DataRow droPage)
    {
        try
        {
            if (!droPage.Table.Columns.Contains("page_desc")) return "";
            if (droPage["page_desc"].ToString().Trim() == "") return "";
            return "&nbsp;<img id=\"page_tooltip_img\" style=\"cursor:pointer;\" src=\"Images/collapse3.gif\" onClick=\"javascript:showHideTooltipDIV();\" border=\"0\"></img>";
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error : RoleSecurity: getTootipIcon() :" + e.Message);
            return "";
        }
    }

    private string getTooltipContent(DataRow droPage)
    {
        try
        {
            if (!droPage.Table.Columns.Contains("page_desc")) return "";
            if (droPage["page_desc"].ToString().Trim() == "") return "";
            return getContent(HttpContext.Current.Server.MapPath("") + @"\scripts\pagetooltipcontent.txt").Replace("<<content>>", CommonFunctions.SafeEncode(droPage["page_desc"].ToString()));
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error : RoleSecurity: getTooltipContent() :" + e.Message);
            return "";
        }
    }

    private string getContent(string fileName)
    {
        try
        {
            if (!File.Exists(fileName))
                return "";
            string temp = "";
            StreamReader sr = new StreamReader(fileName);
            temp = sr.ReadToEnd();
            sr.Close();
            sr = null;
            return temp;
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error : RoleSecurity: getContent() :" + e.Message);
            return "";
        }
    }
    #endregion

    private void loadOwneridDropDown()
    {
        try
        {
            if (Request.QueryString["PK"] == null)
            {
                p_rol_owner_id.Value = Session["user_afrowid"].ToString();
                txt_p_rol_owner_id.Text = Session["userid"].ToString();
            }
            if (Request.QueryString["PK"] != null)
            {
                if (Request.QueryString["CPY"] != null)
                {
                    p_rol_owner_id.Value = Session["user_afrowid"].ToString();
                    txt_p_rol_owner_id.Text = Session["userid"].ToString();
                }

            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: loadOwneridDropDown() :" + ex.Message);
        }
    }

    private void CheckForChangeOwner()
    {
        try
        {
            security sec = new security();
            bool status = false;
            status = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
            if (status == false)
            {
                txt_p_rol_owner_id.Enabled = false;
                imgOwnerSearch.Visible = false;
            }
            sec = null;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: CheckForChangeOwner() :" + ex.Message);
        }
    }

    private void putPrintButtons()
    {
        security HDS = new security();
        try
        {
            if (HDS.getObjectRightsForUser(dsePageInfo.Tables["Page"].Rows[0]["object_id"].ToString(), "read"))
            {
                Label cc = (Label)frmObj.FindControl("ContentPlaceHolder3").FindControl("lblPrintButton");
                if (cc == null) return;

                ImageButton bPrint = new ImageButton();
                bPrint = new ImageButton();
                bPrint.ID = "btnprintTop";
                bPrint.ToolTip = "Printer friendly page";
                bPrint.CausesValidation = false;
                bPrint.ImageUrl = "images/mb_button_print.GIF";
                //b.Attributes.Add("OnClick", "javascript:disableThis('ctl00_ContentPlaceHolder3_btnCpyTop','Loading...');");
                //b.Click += new ImageClickEventHandler(btnCpy_Click);
                bPrint.OnClientClick = "javascript:Popup=(window.open('Print.aspx?pgs_id=" + strPagesetRowId + "&PK=" + Request.QueryString["PK"].ToString() + "&mn=" + Request.QueryString["mn"].ToString() + "','Popup','toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=630,left=100,top=30')||window).focus(); return false;";
                cc.Controls.Add(bPrint);
                cc.Controls.Add(new LiteralControl("&nbsp;"));
            }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error: RoleSecurity: putHeaderButtons()" + e.Message);
        }
    }

    private void isViewMode()
    {
        security HDS = new security();
        bool create = false, edit = false, delete = false;
        try
        {
            if (HttpContext.Current.Request.QueryString["VMODE"] != null)
                if (HttpContext.Current.Request.QueryString["VMODE"] == "1")
                {
                    HDS.getPagesetRights(strPagesetRowId, ref create, ref edit, ref delete);

                    Label cc = (Label)frmObj.FindControl("ContentPlaceHolder3").FindControl("lblViewButton");
                    if (cc == null) return;

                    if (edit)
                    {
                        ImageButton bEdit = new ImageButton();
                        bEdit = new ImageButton();
                        bEdit.ID = "btnEditTop";
                        bEdit.ImageUrl = "images/mb_button_edit.gif";
                        bEdit.ToolTip = "Edit";
                        bEdit.CausesValidation = false;
                        // bEdit.Attributes.Add("OnClick", "javascript:disableThis('ctl00_ContentPlaceHolder3_btnEditTop','Loading...');");
                        bEdit.Click += new ImageClickEventHandler(btnEdit_Click);
                        cc.Controls.Add(bEdit);
                        cc.Controls.Add(new LiteralControl("&nbsp;"));
                    }

                    if (create)
                    {
                        ImageButton bCopy = new ImageButton();
                        bCopy = new ImageButton();
                        bCopy.ID = "btnCpyTop";
                        bCopy.ToolTip = "Copy";
                        bCopy.CausesValidation = false;
                        bCopy.ImageUrl = "images/mb_button_copy.gif";
                        //bCopy.Attributes.Add("OnClick", "javascript:disableThis('ctl00_ContentPlaceHolder3_btnCpyTop','Loading...');");
                        bCopy.Click += new ImageClickEventHandler(btnCpy_Click);
                        cc.Controls.Add(bCopy);
                        cc.Controls.Add(new LiteralControl("&nbsp;"));
                    }

                    if (delete)
                    {
                        bool bDeleteOverride = true;
                        String sDelete_RowId = "";
                        getDelOverrideAccess(ref bDeleteOverride, dsePageInfo.Tables["page"].Rows[0]["page_id"].ToString(), dsePageInfo.Tables["page"].Rows[0]["page_table_name"].ToString(), ref sDelete_RowId);

                        ImageButton bDel = new ImageButton();
                        bDel = new ImageButton();
                        bDel.ID = "btnDelTop";
                        bDel.ToolTip = "Delete";
                        bDel.CausesValidation = false;
                        bDel.ImageUrl = "images/mb_button_delete.gif";
                        //b.Attributes.Add("OnClick", "javascript:disableThis('ctl00_ContentPlaceHolder3_btnDelTop','Deleting...');");           
                        if (bDeleteOverride)
                            bDel.OnClientClick = @"javascript:if(!confirm(""Are you sure you want to delete this Record ?"")){return false;};";
                        else
                            bDel.OnClientClick = @"javascript:alert('You do not have access to delete');return false;";
                        bDel.Click += new ImageClickEventHandler(btnDel_Click);
                        cc.Controls.Add(bDel);
                        cc.Controls.Add(new LiteralControl("&nbsp;"));
                    }

                    //putPrintButtons();

                    p_rol_role_id.Enabled = false;
                    p_rol_role_name.Enabled = false;
                    p_rol_default_dashboard.Enabled = false;

                    btnSave.Visible = false;
                    btnSave_bottom.Visible = false;
                    btnUpdate.Visible = false;
                    btnUpdate_bottom.Visible = false;
                    btnReset.Visible = false;
                    btnReset_bottom.Visible = false;
                }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error: RoleSecurity: isViewMode()" + e.Message);
        }
    }

    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            bool bEditOverride = true;
            String sEdit_RowId = "";
            getEditOverrideAccess(ref bEditOverride, dsePageInfo.Tables["page"].Rows[0]["page_id"].ToString(), dsePageInfo.Tables["page"].Rows[0]["page_table_name"].ToString(), ref sEdit_RowId);

            if (bEditOverride)
            {
                string url = Request.Url.ToString().ToLower();
                url = url.ToString().Replace("&vmode=1", "").Replace("&vmode=0", "");
                if (url != "")
                    if (Request.QueryString["PK"] != null)
                        Response.Redirect(url, true);
            }
            else
            {
                String url = @"" + "NoAccess.aspx" + @"?pgs_id=" + strPagesetRowId + "&PK=" + sEdit_RowId
                                    + "&mn=" + Request.QueryString["mn"] + @"";
                Response.Redirect(url, true);
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: btnEdit_Click() : " + ex.Message);
        }

    }
    protected void btnCpy_Click(object sender, EventArgs e)
    {
        try
        {
            string url = Request.Url.ToString().ToLower();
            url = url.ToString().Replace("&vmode=1", "").Replace("&vmode=0", "");
            url = url + "&CPY=0";
            if (url != "")
                if (Request.QueryString["PK"] != null)
                    Response.Redirect(url, true);
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: btnCpy_Click() : " + ex.Message);
        }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            string strDelKey = "";
            string strPagesetRowId = "";
            if (Request.QueryString["pgs_id"] != null)
                strPagesetRowId = Request.QueryString["pgs_id"].ToString();

            if (Request.QueryString["PK"] != null)
                strDelKey = Request.QueryString["PK"].ToString().Replace("'", "''");
        
            if (strDelKey != "")
            {
                string ret = Navigator.getURL(Request.Url.ToString());
                if (ret != "")
                {
                    if (ret.Contains("DisplayGrid.aspx"))
                    {
                        DataSet dsePageInfo = new DataSet();
                        PageInfoLoad PIL = new PageInfoLoad();
                        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowId);

                        Master MA = new Master();
                        bool blnStatus = MA.ProcessOperation(dsePageInfo, strDelKey, "DELETE");
                        if (blnStatus)
                        {
                            HDDatabase hdd = new HDDatabase();
                            string sQuery = "delete from sy_rol_acc where role_id = '" + strDelKey + "';delete from sy_obj_acc where role_id = '" + strDelKey + "';delete from sy_report_acc where role_id = '" + strDelKey + "';delete from sy_quick_link_access where role_id = '" + strDelKey + "';";
                            SqlCommand sql = new SqlCommand(sQuery);
                            int executed = hdd.ExecuteCmdObj(sql, true);
                            Response.Redirect(ret, true);
                        }
                    }
                    else Response.Redirect(ret, true);
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: btnDel_Click() : " + ex.Message);
        }
    }

    private void getEditOverrideAccess(ref bool bEdit, String Page_id, string Object_Table_Name, ref String Edit_rowid)
    {
        try
        {
            HDDatabase HDD = new HDDatabase();
            DataSet dsTemp = HDD.GetDataset("select * from sy_object_access_override where object='" + Page_id + "' and action='edit' and active='1';");

            foreach (DataRow dr in dsTemp.Tables[0].Rows)
            {
                switch (dr["action"].ToString().ToLower())
                {
                    case "edit":
                        bool bRecord = getOverrideForThisRecord(dr["condition"].ToString());
                        if (bRecord)
                        {
                            if (dr["mode"].ToString().ToLower() == "enable")
                                bEdit = true;
                            else if (dr["mode"].ToString().ToLower() == "disable")
                                bEdit = false;
                            Edit_rowid = dr["af_row_id"].ToString();
                        }
                        break;
                    default:
                        break;
                }
            }
            dsTemp.Dispose();
            dsTemp = null;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: getEditOverrideAccess() : " + ex.Message);
        }
    }
    private bool getOverrideForThisRecord(String Condition)
    {
        bool bRet = true;
        try
        {
            HDDatabase HDD = new HDDatabase();
            String sSql = "select af_row_id from " + dsePageInfo.Tables["page"].Rows[0]["page_table_name"].ToString() + " where af_row_id='" + Request.QueryString["PK"] + "'";
            if (Condition != "")
                sSql = "select af_row_id from " + dsePageInfo.Tables["page"].Rows[0]["page_table_name"].ToString() + " where af_row_id='" + Request.QueryString["PK"] + "' and " + Condition;
            
            String sRet = HDD.GetColumnValue(sSql);
            if (sRet != "")
                bRet = true;
            else
                bRet = false;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: getOverrideForThisRecord() : " + ex.Message);
        }
        return bRet;
    }
    private void getDelOverrideAccess(ref bool bDelete, String Page_id, string Object_Table_Name, ref String Delete_rowid)
    {
        try
        {
            HDDatabase HDD = new HDDatabase();
            DataSet dsTemp = HDD.GetDataset("select * from sy_object_access_override where object='" + Page_id + "' and action='delete' and active='1';");

            foreach (DataRow dr in dsTemp.Tables[0].Rows)
            {
                switch (dr["action"].ToString().ToLower())
                {
                    case "delete":
                        bool bRecord1 = getOverrideForThisRecord(dr["condition"].ToString());
                        if (bRecord1)
                        {
                            if (dr["mode"].ToString().ToLower() == "enable")
                                bDelete = true;
                            else if (dr["mode"].ToString().ToLower() == "disable")
                                bDelete = false;
                            Delete_rowid = dr["message"].ToString();
                        }
                        break;
                    default:
                        break;
                }
            }
            dsTemp.Dispose();
            dsTemp = null;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: getDelOverrideAccess() : " + ex.Message);
        }
    }

    private string wrapItAsMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (!p_rol_role_id.Visible)
                if (p_rol_role_id.Text == "" || Request.QueryString["CPY"] != null)
                    p_rol_role_id.Text = p_rol_role_name.Text.Replace(" ", "_");
            if (SaveData())
            {
                SaveChildElement();
                string refURL = getRefURL();
                if (refURL.Length > 0)
                    Response.Redirect(refURL);
                else
                    lblMessage.Text = wrapItAsMessage("Data Inserted Successfully", false);
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: btnSave_Click() : " + ex.Message);
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            if (UpdateData())
            {
                SaveChildElement();
                string refURL = getRefURL();
                if (refURL.Length > 0)
                    Response.Redirect(refURL);
                else
                    lblMessage.Text = wrapItAsMessage("Data Inserted Successfully", false);
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: btnUpdate_Click() : " + ex.Message);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        try
        {
            string strPageUrl = Request.Url.ToString();
            Response.Redirect(strPageUrl);
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: btnReset_Click() : " + ex.Message);
        }
    }

    private bool SaveData()
    {
        bool blnStatus = true;
        try
        {
            ScreenReader SR = new ScreenReader();
            dseInputInfo = SR.CaptureData(strPagesetRowId, frmObj, dsePageInfo, true);
            if (SR.errormessage != "")
            {
                lblMessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. Error: " + HttpUtility.HtmlEncode(SR.errormessage), true); ;
                return false;
            }
            Master MA = new Master();
            blnStatus = MA.ProcessOperation(dsePageInfo, dseInputInfo, "INSERT");
            if (blnStatus == false)
                lblMessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. Error: " + HttpUtility.HtmlEncode(MA.ErrorMessage), true);
            else
                lblMessage.Text = wrapItAsMessage("&nbsp;<img src='Images/info.gif' border='0'>&nbsp;Data Inserted Successfully.", false);//changed by prithi on 07-Aug-2008
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: SaveData() : " + ex.Message);
            return blnStatus;
        }
        return blnStatus;
    }

    private bool UpdateData()
    {
        bool blnStatus = true;
        try
        {
            ScreenReader SR = new ScreenReader();
            dseInputInfo = SR.CaptureData(strPagesetRowId, frmObj, dsePageInfo, false);
            if (SR.errormessage != "")
            {
                lblMessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Update not successful. Error: " + HttpUtility.HtmlEncode(SR.errormessage), true);
                return false;
            }
            Master MA = new Master();
            blnStatus = MA.ProcessOperation(dsePageInfo, dseInputInfo, "UPDATE");
            if (blnStatus == false)
                lblMessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Update not successful. Error: " + HttpUtility.HtmlEncode(MA.ErrorMessage), true);
            else
                lblMessage.Text = wrapItAsMessage("&nbsp;<img src='Images/info.gif' border='0'>&nbsp;Data Updated Successfully.", false);//changed by prithi on 07-Aug-2008
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : RoleSecurity: UpdateData() : " + ex.Message);
            return blnStatus;
        }
        return blnStatus;
    }

    private void SaveChildElement()
    {
        ScreenReader sr = new ScreenReader();
        HDDatabase hdd = new HDDatabase();
        DataTable dtTemp = new DataTable();
        StringBuilder sbQuery = new StringBuilder();
        bool isCopy=false;
        try
        {
            if (Request.QueryString["CPY"] != null && Request.QueryString["CPY"] == "0")
                isCopy = true;
            if (dsChildElement != null && dsChildElement.Tables.Count > 0)
            {
                foreach (DataTable dt in dsChildElement.Tables)
                {
                    if (!dt.Columns.Contains("read"))
                    {
                        if (isCopy)
                        {
                            DataColumn dc = dt.Columns["is_accessible"];
                            dc.Expression = "";
                        }
                        dt.AcceptChanges();
                        foreach (DataRow dr in dt.Rows)
                        {
                            CheckBox chkBox = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_access_" + dr["af_row_id"].ToString());
                            if (chkBox != null && chkBox.Checked && dr["is_accessible"].ToString() != "True")
                                dr["is_accessible"] = true;
                            else if (chkBox != null && !chkBox.Checked && dr["is_accessible"].ToString() != "False" && dr["is_accessible"].ToString() != "")
                                dr["is_accessible"] = false;
                        }
                    }
                    else
                    {
                        if (isCopy)
                        {
                            DataColumn dcRead = dt.Columns["read"];
                            dcRead.Expression = "";
                            DataColumn dcCreate = dt.Columns["create"];
                            dcCreate.Expression = "";
                            DataColumn dcEdit = dt.Columns["edit"];
                            dcEdit.Expression = "";
                            DataColumn dcDelete = dt.Columns["delete"];
                            dcDelete.Expression = "";
                            DataColumn dcChangeOwner = dt.Columns["change_owner"];
                            dcChangeOwner.Expression = "";
                        }
                        dt.AcceptChanges();
                        foreach (DataRow dr in dt.Rows)
                        {
                            CheckBox chkBox_read = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_read_" + dr["af_row_id"].ToString());
                            if (chkBox_read != null && chkBox_read.Checked && dr["read"].ToString() != "True")
                                dr["read"] = true;
                            else if (chkBox_read != null && !chkBox_read.Checked && dr["read"].ToString() != "False" && dr["read"].ToString() != "")
                                dr["read"] = false;
                            CheckBox chkBox_create = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_create_" + dr["af_row_id"].ToString());
                            if (chkBox_create != null && chkBox_create.Checked && dr["create"].ToString() != "True")
                                dr["create"] = true;
                            else if (chkBox_create != null && !chkBox_create.Checked && dr["create"].ToString() != "False" && dr["create"].ToString() != "")
                                dr["create"] = false;
                            CheckBox chkBox_edit = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_edit_" + dr["af_row_id"].ToString());
                            if (chkBox_edit != null && chkBox_edit.Checked && dr["edit"].ToString() != "True")
                                dr["edit"] = true;
                            else if (chkBox_edit != null && !chkBox_edit.Checked && dr["edit"].ToString() != "False" && dr["edit"].ToString() != "")
                                dr["edit"] = false;
                            CheckBox chkBox_delete = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_delete_" + dr["af_row_id"].ToString());
                            if (chkBox_delete != null && chkBox_delete.Checked && dr["delete"].ToString() != "True")
                                dr["delete"] = true;
                            else if (chkBox_delete != null && !chkBox_delete.Checked && dr["delete"].ToString() != "False" && dr["delete"].ToString() != "")
                                dr["delete"] = false;
                            CheckBox chkBox_change_owner = (CheckBox)frmObj.FindControl("ContentPlaceHolder3").FindControl("chk_change_owner_" + dr["af_row_id"].ToString());
                            if (chkBox_change_owner != null && chkBox_change_owner.Checked && dr["change_owner"].ToString() != "True")
                                dr["change_owner"] = true;
                            else if (chkBox_change_owner != null && !chkBox_change_owner.Checked && dr["change_owner"].ToString() != "False" && dr["change_owner"].ToString() != "")
                                dr["change_owner"] = false;
                        }
                    }

                    dtTemp = new DataTable();
                    dtTemp = dt.GetChanges();
                    if (dtTemp != null && dtTemp.Rows.Count > 0)
                    {
                        if (dtTemp.Columns.Contains("menu_id"))
                        {
                            foreach (DataRow dr in dtTemp.Rows)
                            {
                                if (dr["rol_af_row_id"].ToString() != "" && !isCopy)
                                    sbQuery.Append("UPDATE [sy_rol_acc] SET [is_accessible] = " + (dr["is_accessible"].ToString() == "True" ? "1" : "0") + ",[modified_at] = '" + System.DateTime.Now.ToUniversalTime().ToString() + "',[modified_by] = '" + HttpContext.Current.Session["user_afrowid"].ToString() + "' WHERE [af_row_id] = '" + dr["rol_af_row_id"].ToString() + "';");
                                else
                                    sbQuery.Append("INSERT INTO [sy_rol_acc]([af_row_id],[role_id],[menu_id],[is_accessible],[created_by],[created_at],[modified_at],[modified_by],[owner_id])VALUES('" + sr.getHashKey() + "','" + dseInputInfo.Tables[0].Rows[0]["af_row_id"].ToString() + "','" + dr["af_row_id"].ToString() + "'," + (dr["is_accessible"].ToString() == "True" ? "1" : "0") + ",'" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "');");
                            }
                        }
                        else if (dt.Columns.Contains("rpt_id"))
                        {
                            foreach (DataRow dr in dtTemp.Rows)
                            {
                                if (dr["rol_af_row_id"].ToString() != "" && !isCopy)
                                    sbQuery.Append("UPDATE [sy_report_acc] SET [is_accessible] = " + (dr["is_accessible"].ToString() == "True" ? "1" : "0") + ",[modified_at] = '" + System.DateTime.Now.ToUniversalTime().ToString() + "',[modified_by] = '" + HttpContext.Current.Session["user_afrowid"].ToString() + "' WHERE [af_row_id] = '" + dr["rol_af_row_id"].ToString() + "';");
                                else
                                    sbQuery.Append("INSERT INTO [sy_report_acc]([af_row_id],[role_id],[report_id],[is_accessible],[created_by],[created_at],[modified_at],[modified_by],[owner_id])VALUES('" + sr.getHashKey() + "','" + dseInputInfo.Tables[0].Rows[0]["af_row_id"].ToString() + "','" + dr["af_row_id"].ToString() + "'," + (dr["is_accessible"].ToString() == "True" ? "1" : "0") + ",'" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "');");
                            }
                        }
                        else if (dt.Columns.Contains("link_name"))
                        {
                            foreach (DataRow dr in dtTemp.Rows)
                            {
                                if (dr["rol_af_row_id"].ToString() != "" && !isCopy)
                                    sbQuery.Append("UPDATE [sy_quick_link_access] SET [is_accessible] = " + (dr["is_accessible"].ToString() == "True" ? "1" : "0") + ",[modified_at] = '" + System.DateTime.Now.ToUniversalTime().ToString() + "',[modified_by] = '" + HttpContext.Current.Session["user_afrowid"].ToString() + "' WHERE [af_row_id] = '" + dr["rol_af_row_id"].ToString() + "';");
                                else
                                    sbQuery.Append("INSERT INTO [sy_quick_link_access]([af_row_id],[role_id],[quick_link],[is_accessible],[created_by],[created_at],[modified_at],[modified_by],[owner_id])VALUES('" + sr.getHashKey() + "','" + dseInputInfo.Tables[0].Rows[0]["af_row_id"].ToString() + "','" + dr["af_row_id"].ToString() + "'," + (dr["is_accessible"].ToString() == "True" ? "1" : "0") + ",'" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "');");
                            }
                        }
                        else
                        {
                            foreach (DataRow dr in dtTemp.Rows)
                            {
                                if (dr["rol_af_row_id"].ToString() != "" && !isCopy)
                                    sbQuery.Append("UPDATE [sy_obj_acc] SET [read] = " + (dr["read"].ToString() == "True" ? "1" : "0") + ", [create] = " + (dr["create"].ToString() == "True" ? "1" : "0") + ", [edit] = " + (dr["edit"].ToString() == "True" ? "1" : "0") + ", [delete] = " + (dr["delete"].ToString() == "True" ? "1" : "0") + ", [change_owner] = " + (dr["change_owner"].ToString() == "True" ? "1" : "0") + ", [modified_at] = '" + System.DateTime.Now.ToUniversalTime().ToString() + "',[modified_by] = '" + HttpContext.Current.Session["user_afrowid"].ToString() + "' WHERE [af_row_id] = '" + dr["rol_af_row_id"].ToString() + "';");
                                else
                                    sbQuery.Append("INSERT INTO [sy_obj_acc]([af_row_id],[role_id],[object_id],[read],[create],[edit],[delete],[change_owner],[created_by],[created_at],[modified_at],[modified_by],[owner_id])VALUES('" + sr.getHashKey() + "','" + dseInputInfo.Tables[0].Rows[0]["af_row_id"].ToString() + "','" + dr["object_id"].ToString() + "'," + (dr["read"].ToString() == "True" ? "1" : "0") + "," + (dr["create"].ToString() == "True" ? "1" : "0") + "," + (dr["edit"].ToString() == "True" ? "1" : "0") + "," + (dr["delete"].ToString() == "True" ? "1" : "0") + "," + (dr["change_owner"].ToString() == "True" ? "1" : "0") + ",'" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + System.DateTime.Now.ToUniversalTime().ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "');");
                            }
                        }
                    }
                }
                if (sbQuery.ToString() != "")
                {
                    SqlCommand sql = new SqlCommand(sbQuery.ToString());
                    int executed = hdd.ExecuteCmdObj(sql, true);
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: SaveChildElement() : " + ex.Message);
        }
        finally
        {
            if (dtTemp != null)
                dtTemp.Dispose();
            sbQuery.Clear();
        }
    }

    private string getRefURL()
    {
        try
        {
            return "DisplayGrid.aspx?pgs_id=" + Request.QueryString["pgs_id"].ToString() + "&mn=" + Request.QueryString["mn"].ToString();
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error: RoleSecurity: getRefURL() : " + ex.Message);
            return "";
        }
    }

}